package cn.edu.scau.cmi.shishuai.exercise10;

import java.text.DecimalFormat;

public class ConsoleClient_Example9_18 {
	public static void main(String[] args) {
		double number = 9876.123456;
		System.out.println(number + "格式化为整数最少六位，小数最多3位");
		DecimalFormat dFormat = new DecimalFormat("000000.000");
		String result= dFormat.format(number);
		System.out.println(result);
		number = 12345678.987654;
		System.out.printf("%f 格式化位整数至少2位，小数至多4位(整数部分按千分组): %n", number);
		dFormat.applyPattern("0.0000%");
		result = dFormat.format(number);
		System.out.println(result);
		number = 0.98765;
		System.out.println(number + "格式化为百分数和千分数：");
		dFormat.applyPattern("0.0000%");
		System.out.println(dFormat.format(number));
		dFormat.applyPattern("0.0000\u2030");
		result = dFormat.format(number);
		System.out.println(result);
		String money = "9,567,769,345￥";
		System.out.println(money + "格式化为数字");
		dFormat.applyPattern("#,##,##0.000");
		try {
			Number number2 = dFormat.parse(money);
			System.out.println(number2.doubleValue());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
